#include <opencv/cv.h>
#include "opencv2/opencv.hpp"
#include <opencv/highgui.h>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/nonfree/features2d.hpp>
#include <opencv2/flann/flann.hpp>
#include <opencv2/flann/flann_base.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/contrib/contrib.hpp>
#include <string>
#include "opencv2/calib3d/calib3d.hpp"
#include "Frame.h"
#include "PointData.h"
#include "SparseBundleAdjustment.h"

#define TEMPLATE_SIZE 7
#define ROI_SIZE 15

using namespace std;
using namespace cv;

class Tracker
{
public:
    static const int min_features = 25;
	int keypoint_threshold;
	string filename;
	vector<Frame*> frames;
	double ncc_threshold;
	vector<Point3f> points_3d;
	int last_key;
	VideoCapture cap;
	Mat prev_frame;
	Mat k;
	int frame_index;
	int alive_keypoints_c;
	SparseBundleAdjustment minimizer;
	Tracker(string filename,double ncc_threshold = 0.6,int keypoint_threshold = 2500):filename(filename),ncc_threshold(ncc_threshold),keypoint_threshold(keypoint_threshold), frames(),alive_keypoints_c(0),minimizer(){}
	Rect getRectangle(double x,double y,double x_offset,int y_offset,Size frameSize);
	void track();
    void myCalibrateCamera();
private:
	void printDataToFile(const char* camera_filename,const char* points_filename);
	void performSBA();
	
};

